﻿@model EventSys.BussinesEntities.Director

@*<script src="~/Scripts/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>*@

@{
    <h2 id="commonMessage" style = "color : blue"></h2>
    
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<script type="text/javascript">
    $(function () {
        $("#dni").focusout(function(){
            var dni = $(this).val();
            //alert(dni);
            $.ajax({
                url: "/Director/validarDni?dni=" + dni,
                success: (function (data) {
                    //alert(dni);
                    if (data.existe == true) {
                        alert("El DNI ya existe");
                        $("#dni").focus().select();
                    }
                })
            })
        })
    })

    $(document).ready(function () {
        $("#dni").keydown(function (e) {
            // Permite: backspace, delete, tab, escape, enter and .
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
                // Permite: Ctrl+A -----> para seleccionar todo el texto de la casilla
                (e.keyCode == 65 && e.ctrlKey === true) ||
                // Perimite: home, end, left, right
                (e.keyCode >= 35 && e.keyCode <= 39)) {
                    // deja que suceda todo, no hacer nada
                    return;
                }
            // Se asegura de que se trata de un número y detiene la pulsación de tecla
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        });
    });

    //////////////////

    function loadCarrera() {
        $(this).load(function () {
            $("#idCarrera").reload();
        })
        $.getJSON("/Director/refreshCarrera", null, function (data) {
            var selectList = $("#idCarrera");
            selectList.empty();
            $.each(data, function (index, optionData) {
                var option = $('<option>').text(optionData.Text).val(optionData.Value);
                selectList.append(option);
            });
            //Notificacion tipo twitter
            $('#commonMessage').html("Se ha agregado una Nueva Carrera");
            $('#commonMessage').delay(1000).slideDown(400).delay(3000).slideUp(400);
        });
    }

    function OnSuccessAdd(data) {
        console.log("agregando ventana");
        $("#dialogAdd").dialog({
            modal: true,
            width: 350,
            //autoOpen: false,
            buttons: {
                'Cerrar': function () {
                    $(this).dialog('close');
                },
                'Guardar': function () {
                    $.validator.unobtrusive.parse('#frmCreate');
                    $("#frmCreate").submit();
                }
            },
            close: function () {
                $(this).parent().remove();
                $(this).remove();
            }
        });
    }

    function OnSuccessCreate(data) {

        //alert(data.me)
        if (data.ok == true) {
            //alert(data.msg); // mostrara el mensaje de guardado correctamente
            loadCarrera();
            $("#dialogAdd").dialog('close');
        }
        else {
            alert('ERROR:' + data.msg);
        }
    }
</script>


<h2>REGISTRAR DIRECTORES</h2>


@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Director</legend>

        <div class="editor-label">
            @Html.HiddenFor(model => model.idDirector)
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.idDirector)
            @Html.ValidationMessageFor(model => model.idDirector)
        </div>

        <table CELLPADDING=4 CELLSPACING=4>
            <tbody>

                <tr>
                    <td>  DNI:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.DNI)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.DNI, new { style = "width: 150px;", placeholder = "Ingrese DNI", minlength = "8", maxlength = "8", id = "dni" })
            @Html.ValidationMessageFor(model => model.DNI)
        </div>
            </td>
                    <td>  NOMBRES:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Nombre)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Nombre, new { style = "width: 280px;", placeholder = "Ingrese Nombres" })
            @Html.ValidationMessageFor(model => model.Nombre)
        </div>
              </td>
              
                    <td>  APELLIDOS:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Apellidos)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Apellidos, new { style = "width: 280px;", placeholder = "Ingrese Apellidos" })
            @Html.ValidationMessageFor(model => model.Apellidos)
        </div>
                        </td>
                    </tr>
                <tr>

                    <td>  DIRECCION:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Dirección)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Dirección, new { style = "width: 280px;", placeholder = "Ingrese Dirección" })
            @Html.ValidationMessageFor(model => model.Dirección)
        </div>

                
                    <td>  TELEFONO:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Telefono)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Telefono, new { style = "width: 280px;", placeholder = "Ingrese Telefono" })
            @Html.ValidationMessageFor(model => model.Telefono)
        </div>
               </td>
                    </tr>

                <tr>

                    <td>  CELULAR:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Celular)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Celular, new { style = "width: 280px;", placeholder = "Ingrese Celular" })
            @Html.ValidationMessageFor(model => model.Celular)
        </div>
               
             
                    <td> EMAIL:  </td>
                    <td>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Email, new { style = "width: 280px;", placeholder = "Ingrese Email" })
            @Html.ValidationMessageFor(model => model.Email)
        </div>
                </td>
                 </tr>

        <div class="editor-label">
            @Html.LabelFor(model => model.idCarrera)
        </div>
        <div class="editor-field">
            @*@Html.EditorFor(model => model.idCarrera)*@
            @Html.DropDownList("idCarrera")
            @Html.ValidationMessageFor(model => model.idCarrera)

            
                @Ajax.ActionLink("Nueva Carrera", "Create", new AjaxOptions()
           {
               Url = Url.Action("_Create", "Carrera"),
               UpdateTargetId = "showAdd",
               OnSuccess = "OnSuccessAdd"
           })
            
            <p> </p>
        </div>

                 </tbody>
        </table>

         <style>
            table /*#detalleInv*/ {
                background: #FDBB30;
                border-radius: 5px;
                border-spacing: 0px;
                border: solid 1px;
            }

                table /*#detalleInv*/ thead {
                    background: #232322;
                    font-weight: 700;
                    color: white;
                }

            #monto {
                width: 50px;
            }

            #idAusp {
                width: 30px;
                background: #FDBB30;
                text-align: center;
                font-weight: 500;
                border: none;
            }
        </style>


        <p>
            <input type="submit" value="CREAR" class="k-button"/>
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Regresar", "Index")
</div>
<br /> <br />
<div id="showAdd"></div>

@section Scripts {
    @*@Scripts.Render("~/bundles/jqueryval")*@
}
